<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.net.URLDecoder" %>
<%--
  Created by IntelliJ IDEA.
  User: HP
  Date: 2021/10/18
  Time: 20:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录</title>
</head>
<body>
<%
    Cookie[] cookies = request.getCookies();
    String[] s = null;

    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (URLDecoder.decode(cookie.getName(), "utf-8").equals("nameinfo")) {
                String str = URLDecoder.decode(cookie.getValue(), "utf-8");
                s = str.split("-");
            }
        }
    }
%>

<%--利用cookie实现的免密登录--%>
<form action="LoginServlet" method="post">
    <table align="center" width="600px" bgcolor="#f0f8ff" height="320px">
        <%
            if (s != null) {
        %>

        <tr>
            <th colspan="600px" height="120px" align="center"><font size="5px" color="black">登录</font></th>
        </tr>
        <tr>
            <td colspan="600px" height="50px" align="center"><input type="text" name="account" placeholder="请输入账号"
                                                                    value="<%=s[0]%>"></td>
        </tr>
        <tr>
            <td colspan="600px" height="50px" align="center"><input type="password" name="password" placeholder="请输入密码"
                                                                    value="<%=s[1]%>"></td>
        </tr>
        <%
        } else {
        %>
        <tr>
            <th colspan="600px" height="120px" align="center"><font size="5px" color="black">登录</font></th>
        </tr>
        <tr>
            <td colspan="600px" height="50px" align="center"><input type="text" name="account" placeholder="请输入账号"></td>
        </tr>
        <tr>
            <td colspan="600px" height="50px" align="center"><input type="password" name="password" placeholder="请输入密码">
            </td>
        </tr>
        <tr>
            <td colspan="600px" height="50px" align="center"><input type="checkbox" name="remember" value="1">记住我</td>
        </tr>
        <%
            }
        %>
        <tr>
            <th width="260px" height="40px" align="right"><input type="submit" value="登录"></th>
            <th width="118px" align="right"><input type="reset" value="重置"></th>
            <th></th>
            <th></th>
        </tr>
        <tr>
            <th height="60px"></th>
        </tr>
    </table>
</form>

</body>
</html>
